package com.cadre.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cadre.common.utils.SecurityUtils;
import com.cadre.common.utils.oldutil.AgeUtil;
import com.cadre.common.utils.oldutil.DateUtil;
import com.cadre.common.utils.oldutil.PageUtils;
import com.cadre.common.utils.oldutil.Query;
import com.cadre.common.utils.oldutil.officerenum.*;
import com.cadre.system.domain.officer.*;
import com.cadre.system.domain.vo.ESUtil;
import com.cadre.system.mapper.*;
import com.cadre.system.service.A04Service;
import com.cadre.system.service.A79Service;
import com.cadre.system.service.DPersontagService;
import org.apache.commons.lang3.StringUtils;
import org.elasticsearch.action.search.SearchRequest;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.search.SearchHit;
import org.elasticsearch.search.builder.SearchSourceBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;

import java.io.IOException;
import java.util.*;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

@Service("dPersontagService")
public class DPersontagServiceImpl extends ServiceImpl<DPersontagMapper, DPersontagEntity> implements DPersontagService {
    private static final String DEFAULT_VALUE = "其他";
    @Autowired
    private A79Service a79Service;
    @Autowired
    private A04Service a04Service;
    @Autowired
    private A01Mapper a01Mapper;
    @Autowired
    private A19BMapper a19bMapper;
    @Autowired
    private A19Mapper a19Mapper;
    @Autowired
    private DIC_ZBMapper dicZbMapper;
    @Autowired
    RestHighLevelClient client;

    @Override // com.tdqy.cadre.modular.profess.service.DPersontagService
    public PageUtils queryPage(Map<String, Object> params) {
        return new PageUtils(this.baseMapper.selectPage(new Query(params).getPage(), new LambdaQueryWrapper<>()));
    }

    @Override // com.tdqy.cadre.modular.profess.service.DPersontagService
    public PageUtils tagSearch(Map<String, Object> param) throws IOException {
        String[] split;
        String[] split2;
        param.put("page", (String) param.get("pageNum"));
        param.put("limit", (String) param.get("pageSize"));
        Map<String, Object> map = new ToQueryParam().toSql((String) param.get("query"));
        map.put("a0201", new ArrayList<Integer>() { // from class: com.tdqy.cadre.modular.profess.service.impl.DPersontagServiceImpl.1
            {
                add(1);
            }
        });
        Object a0181s = map.get("a0181s");
        if (null != a0181s) {
            Object a0181List = (List) a0181s;
            Map<String, Object> a0181Map = new HashMap<>();
            a0181Map.put("tableName", "DIC_ZB1003");
            a0181Map.put("names", a0181List);
            String flag = "1";
            try {
                flag = (String) map.get("a0181flag");
            } catch (Exception e) {
            }
            a0181Map.put("a0181flag", flag);
            List<DIC_ZB> dic_zb1003 = this.dicZbMapper.selectDICByValid(a0181Map);
            if (!CollectionUtils.isEmpty(dic_zb1003)) {
                map.put("a0201", (List) dic_zb1003.stream().map((v0) -> {
                    return v0.getValid();
                }).distinct().collect(Collectors.toList()));
            }
        }
        if (map != null && !map.isEmpty()) {
            param.putAll(map);
        }
        Object searchParam = param.get("searchParam");
        List<A01> a01s = new ArrayList<>();
        if (null != searchParam) {
            String searchParamStr = ((String) searchParam).trim().replace("，", ",");
            List<String> searchList = Arrays.asList(searchParamStr.split(","));
            Map<String, Object> m = new LinkedHashMap<>();
            for (int i = 0; i < searchList.size(); i++) {
                String str = searchList.get(i);
                m.put("param" + i, str);
                if (str.contains("以上")) {
                    if (str.contains("岁以上")) {
                        split2 = str.split("岁以上");
                    } else {
                        split2 = str.split("以上");
                    }
                    if (split2.length > 0 && StringUtils.isNumeric(split2[0])) {
                        m.put("greater", split2[0]);
                        m.remove("param" + i);
                    }
                } else if (str.contains("以下")) {
                    if (str.contains("岁以下")) {
                        split = str.split("岁以下");
                    } else {
                        split = str.split("以下");
                    }
                    if (split.length > 0 && StringUtils.isNumeric(split[0])) {
                        m.put("less", split[0]);
                        m.remove("param" + i);
                    }
                }
            }
            param.put("searchList", m);
            SearchRequest request = new SearchRequest(new String[]{ESUtil.a01Index});
            SearchSourceBuilder builder = new SearchSourceBuilder();
            builder.from(0);
            builder.size(100);
            builder.query(QueryBuilders.queryStringQuery(searchParamStr).analyzeWildcard(false));
            builder.timeout(TimeValue.timeValueSeconds(1));
            // 添加 _source 字段
            builder.fetchSource(new String[]{"FLOWID","A0101", "A0102", "A0103", "A0104"}, null);
            request.source(builder);
            Iterator it = this.client.search(request, RequestOptions.DEFAULT).getHits().iterator();
            while (it.hasNext()) {
                a01s.add(ESUtil.useObjectMapper(((SearchHit) it.next()).getSourceAsMap()));
            }
        }
        param.put("userid", Long.valueOf(SecurityUtils.getUserId()));
        Object a0142 = param.get("a0142");
        Object a0142full = param.get("a0142full");
        Object a0142notfull = param.get("a0142notfull");
        StringJoiner sj = new StringJoiner(" OR ", "( ", " )");
        if (a0142 != null) {
            sj.add(" TRUNC(months_between(sysdate, a0142)/12) = " + a0142);
        }
        if (a0142full != null) {
            sj.add(" TRUNC(months_between(sysdate, a0142)/12) >= " + a0142full);
        }
        if (a0142notfull != null) {
            sj.add(" TRUNC(months_between(sysdate, a0142)/12) < " + a0142notfull);
        }
        param.put("a0142New", sj.toString().equals("(  )") ? null : sj.toString());
        Object a0185 = param.get("a0185");
        Object a0185full = param.get("a0185full");
        Object a0185notfull = param.get("a0185notfull");
        StringJoiner sj2 = new StringJoiner(" OR ", "( ", " )");
        if (a0185 != null) {
            sj2.add(" TRUNC(months_between(sysdate, A0185)/12) = " + a0185);
        }
        if (a0185full != null) {
            sj2.add(" TRUNC(months_between(sysdate, A0185)/12) >= " + a0185full);
        }
        if (a0185notfull != null) {
            sj2.add(" TRUNC(months_between(sysdate, A0185)/12) < " + a0185notfull);
        }
        param.put("a0185New", sj2.toString().equals("(  )") ? null : sj2.toString());
        Object a0180 = param.get("a0180");
        Object a0180full = param.get("a0180full");
        Object a0180notfull = param.get("a0180notfull");
        StringJoiner sj21 = new StringJoiner(" OR ", "( ", " )");
        if (a0180 != null) {
            sj21.add(" TRUNC(months_between(sysdate, a0180)/12) = " + a0180);
        }
        if (a0180full != null) {
            sj21.add(" TRUNC(months_between(sysdate, a0180)/12) >= " + a0180full);
        }
        if (a0180notfull != null) {
            sj21.add(" TRUNC(months_between(sysdate, a0180)/12) < " + a0180notfull);
        }
        param.put("a0180New", sj21.toString().equals("(  )") ? null : sj21.toString());
        Object a0105 = param.get("a0105");
        Object a0130 = param.get("a0130");
        Object a0184 = param.get("a0184");
        String nsfRaltion = "and";
        try {
            if (param.get("nsfFlag").toString().equals("2")) {
                nsfRaltion = "OR";
            }
        } catch (Exception e2) {
        }
        StringJoiner sj3 = new StringJoiner(nsfRaltion, "( ", " )");
        if (a0105 != null) {
            sj3.add(" a01.a0105  = '" + a0105 + "'");
        }
        if (a0130 != null) {
            sj3.add(" a01.a0130 != '汉族' ");
        }
        if (a0184 != null) {
            sj3.add(" (not regexp_like(a01.a0184A,'(^[+-]?\\d{0,}\\.?\\d{0,}$)' ) or a01.a0184A is null) ");
        }
        param.put("nsf", sj3.toString().equals("(  )") ? null : sj3.toString());
        Page<A01> page = new Query(param).getPage();
        List<A01> list = this.baseMapper.intelligenceTSearch(param);
        list.addAll(a01s);
        List<A01> result = new ArrayList<>();
        for (A01 a : list) {
            if (!result.stream().anyMatch(u -> {
                return u.getFlowid().equals(a.getFlowid());
            })) {
                result.add(a);
            }
        }
        page.setTotal(result.size());
        return new PageUtils(page.setRecords(result));
    }

    @Override // com.tdqy.cadre.modular.profess.service.DPersontagService
    public List<A01> exprotSearch(Map<String, Object> param) {
        String[] split;
        String[] split2;
        Map<String, Object> map = new ToQueryParam().toSql((String) param.get("query"));
        map.put("a0201", new ArrayList<Integer>() { // from class: com.tdqy.cadre.modular.profess.service.impl.DPersontagServiceImpl.2
            {
                add(1);
            }
        });
        Object a0181s = map.get("a0181s");
        if (null != a0181s) {
            Object a0181List = (List) a0181s;
            Map<String, Object> a0181Map = new HashMap<>();
            a0181Map.put("tableName", "DIC_ZB1003");
            a0181Map.put("names", a0181List);
            List<DIC_ZB> dic_zb1003 = this.dicZbMapper.selectDICByValid(a0181Map);
            if (!CollectionUtils.isEmpty(dic_zb1003)) {
                map.put("a0201", (List) dic_zb1003.stream().map((v0) -> {
                    return v0.getValid();
                }).distinct().collect(Collectors.toList()));
            }
        }
        if (map != null && !map.isEmpty()) {
            param.putAll(map);
        }
        Object searchParam = param.get("searchParam");
        if (null != searchParam) {
            List<String> searchList = Arrays.asList(((String) searchParam).trim().replace("，", ",").split(","));
            Map<String, Object> m = new LinkedHashMap<>();
            for (int i = 0; i < searchList.size(); i++) {
                String str = searchList.get(i);
                m.put("param" + i, str);
                if (str.contains("以上")) {
                    if (str.contains("岁以上")) {
                        split2 = str.split("岁以上");
                    } else {
                        split2 = str.split("以上");
                    }
                    if (split2.length > 0 && StringUtils.isNumeric(split2[0])) {
                        m.put("greater", split2[0]);
                        m.remove("param" + i);
                    }
                } else if (str.contains("以下")) {
                    if (str.contains("岁以下")) {
                        split = str.split("岁以下");
                    } else {
                        split = str.split("以下");
                    }
                    if (split.length > 0 && StringUtils.isNumeric(split[0])) {
                        m.put("less", split[0]);
                        m.remove("param" + i);
                    }
                }
            }
            param.put("searchList", m);
        }
        param.put("userid", Long.valueOf(SecurityUtils.getUserId()));
        Object a0142 = param.get("a0142");
        Object a0142full = param.get("a0142full");
        Object a0142notfull = param.get("a0142notfull");
        StringJoiner sj = new StringJoiner(" OR ", "( ", " )");
        if (a0142 != null) {
            sj.add(" TRUNC(months_between(sysdate, a0142)/12) = " + a0142);
        }
        if (a0142full != null) {
            sj.add(" TRUNC(months_between(sysdate, a0142)/12) >= " + a0142full);
        }
        if (a0142notfull != null) {
            sj.add(" TRUNC(months_between(sysdate, a0142)/12) < " + a0142notfull);
        }
        param.put("a0142New", sj.toString().equals("(  )") ? null : sj.toString());
        Object a0185 = param.get("a0185");
        Object a0185full = param.get("a0185full");
        Object a0185notfull = param.get("a0185notfull");
        StringJoiner sj2 = new StringJoiner(" OR ", "( ", " )");
        if (a0185 != null) {
            sj2.add(" TRUNC(months_between(sysdate, A0185)/12) = " + a0185);
        }
        if (a0185full != null) {
            sj2.add(" TRUNC(months_between(sysdate, A0185)/12) >= " + a0185full);
        }
        if (a0185notfull != null) {
            sj2.add(" TRUNC(months_between(sysdate, A0185)/12) < " + a0185notfull);
        }
        param.put("a0185New", sj2.toString().equals("(  )") ? null : sj2.toString());
        Object a0180 = param.get("a0180");
        Object a0180full = param.get("a0180full");
        Object a0180notfull = param.get("a0180notfull");
        StringJoiner sj21 = new StringJoiner(" OR ", "( ", " )");
        if (a0180 != null) {
            sj21.add(" TRUNC(months_between(sysdate, a0180)/12) = " + a0180);
        }
        if (a0180full != null) {
            sj21.add(" TRUNC(months_between(sysdate, a0180)/12) >= " + a0180full);
        }
        if (a0180notfull != null) {
            sj21.add(" TRUNC(months_between(sysdate, a0180)/12) < " + a0180notfull);
        }
        param.put("a0180New", sj21.toString().equals("(  )") ? null : sj21.toString());
        Object a0105 = param.get("a0105");
        Object a0130 = param.get("a0130");
        Object a0184 = param.get("a0184");
        String nsfRaltion = "and";
        try {
            if (param.get("nsfFlag").toString().equals("2")) {
                nsfRaltion = "OR";
            }
        } catch (Exception e) {
        }
        StringJoiner sj3 = new StringJoiner(nsfRaltion, "( ", " )");
        if (a0105 != null) {
            sj3.add(" a01.a0105  = '" + a0105 + "'");
        }
        if (a0130 != null) {
            sj3.add(" a01.a0130 != '汉族' ");
        }
        if (a0184 != null) {
            sj3.add(" (not regexp_like(a01.a0184A,'(^[+-]?\\d{0,}\\.?\\d{0,}$)' ) or a01.a0184A is null) ");
        }
        param.put("nsf", sj3.toString().equals("(  )") ? null : sj3.toString());
        return this.baseMapper.intelligenceTSearch(param);
    }

    @Override // com.tdqy.cadre.modular.profess.service.DPersontagService
    public List<String> getWorkTag(Map<String, Object> map) {
        return this.baseMapper.getWorkTag(map);
    }

    @Override // com.tdqy.cadre.modular.profess.service.DPersontagService
    @Transactional(rollbackFor = {Exception.class})
    public void updateA01Tag(String personid) {
        List<DPersontagEntity> list = getA01TagEntity(personid);
        if (list.size() != 0) {
            LambdaQueryWrapper<DPersontagEntity> lambdaQueryWrapper = new LambdaQueryWrapper();
            lambdaQueryWrapper.eq(DPersontagEntity::getPersonid, personid);
            lambdaQueryWrapper.in(DPersontagEntity::getTagid, A01TagEnum.getValues());
            this.baseMapper.delete(lambdaQueryWrapper);
            this.baseMapper.batchInsert(list);
        }
    }

    @Override // com.tdqy.cadre.modular.profess.service.DPersontagService
    @Transactional(rollbackFor = {Exception.class})
    public void deleteA01Tag(String[] personids) {
        for (String personid : personids) {
            LambdaQueryWrapper<DPersontagEntity> lambdaQueryWrapper = new LambdaQueryWrapper();
            lambdaQueryWrapper.eq(DPersontagEntity::getPersonid, personid);
            this.baseMapper.delete(lambdaQueryWrapper);
        }
    }

    @Override
    @Transactional(rollbackFor = {Exception.class})
    public void updateA79Tag(String personid) {
        List<A79> a79s = this.a79Service.selectList(personid);
        if (a79s.size() != 0) {
            List<DPersontagEntity> list = new ArrayList<>();
            LambdaQueryWrapper<DPersontagEntity> lambdaQueryWrapper = new LambdaQueryWrapper();
            lambdaQueryWrapper.eq(DPersontagEntity::getPersonid, personid);
            lambdaQueryWrapper.in(DPersontagEntity::getTagid, A79TagEnum.getValues());
            this.baseMapper.delete(lambdaQueryWrapper);
            for (A79 a79 : a79s) {
                DPersontagEntity entity = new DPersontagEntity();
                entity.setPersonid(a79.getPersonid());
                entity.setTagid(A79TagEnum.getValueByName(a79.getA7910()));
                entity.setValuestring(a79.getA7921());
                if (a79.getA7922() != null) {
                    entity.setValuedate(a79.getA7922());
                } else {
                    entity.setValuedate(null);
                }
                this.baseMapper.insert(entity);
                list.add(entity);
            }
        }
    }

    @Override // com.tdqy.cadre.modular.profess.service.DPersontagService
    @Transactional(rollbackFor = {Exception.class})
    public void updateA04Tag(String personid) {
        List<DPersontagEntity> list = new ArrayList<>();
        LambdaQueryWrapper<A04> lambdaQueryWrapper = new LambdaQueryWrapper();
        lambdaQueryWrapper.eq(A04::getPersonid, personid);
        lambdaQueryWrapper.orderByAsc(A04::getA0460);
        List<A04> a04s = a04Service.list(lambdaQueryWrapper);
        if (a04s.size() != 0) {
            LambdaQueryWrapper<DPersontagEntity> lambdaQueryWrapper1 = new LambdaQueryWrapper();
            lambdaQueryWrapper1.eq(DPersontagEntity::getPersonid, personid);
            lambdaQueryWrapper1.in(DPersontagEntity::getTagid, A04TagEnum.getValues());
            this.baseMapper.delete(lambdaQueryWrapper1);
            List<A04> a04zuigao = (List) a04s.stream().filter(t -> {
                return t.getA0405() != null && !t.getA0405().equals("");
            }).collect(Collectors.toList());
            if (a04zuigao.size() > 0) {
                DPersontagEntity entity = new DPersontagEntity();
                entity.setPersonid(personid);
                entity.setTagid(Long.valueOf(A04TagEnum.ZUIGAO_XUELI.getValue()));
                entity.setValuestring(XueLiEnum.getValueByName(a04zuigao.get(0).getA0405()));
                list.add(entity);
            }
            for (A04 a04 : a04s) {
                DPersontagEntity tagEntity = new DPersontagEntity();
                tagEntity.setPersonid(personid);
                tagEntity.setTagid(Long.valueOf(A04TagEnum.TONG_XUE.getValue()));
                tagEntity.setValuestring((a04.getA0435() == null ? "" : a04.getA0435() + ",") + (a04.getA0405() == null ? "" : a04.getA0405() + ",") + (a04.getA0411() == null ? "" : a04.getA0411() + ",") + DateUtil.dateToString(a04.getA0430(), DateUtil.YEAR_DATE_FORMAT));
                list.add(tagEntity);
                DPersontagEntity tagEntity1 = new DPersontagEntity();
                tagEntity1.setPersonid(personid);
                tagEntity1.setTagid(Long.valueOf(A04TagEnum.ZHUANYE_LEIBIE.getValue()));
                tagEntity1.setValuestring(ZhuanYeEnum.getValueByName(a04.getA0410() == null ? "00" : a04.getA0410().substring(0, 2)));
                list.add(tagEntity1);
            }
            List<A04> quanriz = (List) a04zuigao.stream().filter(a042 -> {
                return a042.getA0449().equals("1");
            }).collect(Collectors.toList());
            if (quanriz.size() > 0) {
                DPersontagEntity entity1 = new DPersontagEntity();
                entity1.setPersonid(personid);
                entity1.setTagid(Long.valueOf(A04TagEnum.QUANRIZHI_ZUIGAOXUELI.getValue()));
                entity1.setValuestring(XueLiEnum.getValueByName(quanriz.get(0).getA0405()));
                list.add(entity1);
            }
            this.baseMapper.batchInsert(list);
        }
    }

    @Transactional(rollbackFor = {Exception.class})
    public void deleteA19BTagByPersonid(String personid) {
        LambdaQueryWrapper<DPersontagEntity> lambdaQueryWrapper = new LambdaQueryWrapper();
        lambdaQueryWrapper.eq(DPersontagEntity::getPersonid, personid);
        lambdaQueryWrapper.in(DPersontagEntity::getTagid, A19BTagEnum.getValues());
        this.baseMapper.delete(lambdaQueryWrapper);
    }

    @Override // com.tdqy.cadre.modular.profess.service.DPersontagService
    @Transactional(rollbackFor = {Exception.class})
    public void updateA19BTag(String personid) {
        deleteA19BTagByPersonid(personid);
        List<DPersontagEntity> list = new ArrayList<>();
        LambdaQueryWrapper<A19B> lambdaQueryWrapper = new LambdaQueryWrapper();
        lambdaQueryWrapper.eq(A19B::getPersonid, personid);
        List<A19B> a19s = this.a19bMapper.selectList(lambdaQueryWrapper);
        if (a19s.size() != 0) {
            for (String str :  a19s.stream().map(t -> {
                return t.getA1916() + "," + DateUtil.dateToString(t.getA1905(), "yyyy-MM") + "," + DateUtil.dateToString(t.getA1910(), "yyyy-MM");
            }).distinct().collect(Collectors.toList())) {
                DPersontagEntity tagEntity = new DPersontagEntity();
                tagEntity.setPersonid(personid);
                tagEntity.setTagid(Long.valueOf(A19BTagEnum.TONG_SHI.getValue()));
                tagEntity.setValuestring(str);
                list.add(tagEntity);
            }
            this.baseMapper.batchInsert(list);
        }
    }

    @Override // com.tdqy.cadre.modular.profess.service.DPersontagService
    @Transactional(rollbackFor = {Exception.class})
    public void updateA19Tag(String personid) {
        LambdaQueryWrapper<DPersontagEntity> lambdaQueryWrapper = new LambdaQueryWrapper();
        lambdaQueryWrapper.eq(DPersontagEntity::getPersonid, personid);
        lambdaQueryWrapper.in(DPersontagEntity::getTagid, A19TagEnum.getValues());
        this.baseMapper.delete(lambdaQueryWrapper);
        List<DPersontagEntity> list = new ArrayList<>();
        LambdaQueryWrapper<A19> lambdaQueryWrapper1 = new LambdaQueryWrapper();
        lambdaQueryWrapper1.eq(A19::getPersonid, personid);
        lambdaQueryWrapper1.eq(A19::getA1935, 1);
        List<A19> flist = this.a19Mapper.selectList(lambdaQueryWrapper1);
        if (flist.size() != 0) {
            for (A19 a19 : flist) {
                DPersontagEntity tagEntity = new DPersontagEntity();
                tagEntity.setPersonid(personid);
                tagEntity.setTagid(Long.valueOf(A19TagEnum.ZHIWU_LEIB.getValue()));
                if (a19.getA1940() == null) {
                    tagEntity.setValuestring("非领导职务");
                } else {
                    tagEntity.setValuestring(a19.getA1940().shortValue() == 1 ? "领导职务" : "非领导职务");
                }
                list.add(tagEntity);
            }
            for (String str :  flist.stream().map(t -> {
                return t.getA1960();
            }).filter(s -> {
                return s != null;
            }).collect(Collectors.toList())) {
                DPersontagEntity tagEntity2 = new DPersontagEntity();
                tagEntity2.setPersonid(personid);
                tagEntity2.setTagid(Long.valueOf(A19BTagEnum.RENZHI_LAIYUAN.getValue()));
                tagEntity2.setValuestring(str);
                list.add(tagEntity2);
            }
            for (String str2 :  flist.stream().map(t -> {
                return t.getA1970();
            }).filter(s -> {
                return s != null;
            }).collect(Collectors.toList())) {
                DPersontagEntity tagEntity3 = new DPersontagEntity();
                tagEntity3.setPersonid(personid);
                tagEntity3.setTagid(Long.valueOf(A19TagEnum.ZHIWU_LEIB.getValue()));
                tagEntity3.setValuestring(str2);
                list.add(tagEntity3);
            }
            this.baseMapper.batchInsert(list);
        }
    }

    @Override
    @Transactional(rollbackFor = {Exception.class})
    public void initPersonTag(List<Map<String, Object>> a01List) {
        for (Map<String, Object> person : a01List) {
            String personid = person.get("FLOWID").toString();
            updateA01Tag(personid);
            updateA04Tag(personid);
            updateA19Tag(personid);
            updateA19BTag(personid);
            updateA79Tag(personid);
        }
    }

    public List<DPersontagEntity> getA01TagEntity(String personid) {
        A01 person = (A01) this.a01Mapper.selectById(personid);
        List<DPersontagEntity> list = new ArrayList<>();
        if (person == null) {
            return list;
        }
        DPersontagEntity nameTag = new DPersontagEntity();
        nameTag.setPersonid(person.getFlowid());
        nameTag.setTagid(Long.valueOf(A01TagEnum.XING_MING.getValue()));
        nameTag.setValuestring(person.getA0101() == null ? DEFAULT_VALUE : person.getA0101());
        list.add(nameTag);
        DPersontagEntity sexTag = new DPersontagEntity();
        sexTag.setPersonid(person.getFlowid());
        sexTag.setTagid(Long.valueOf(A01TagEnum.XING_BIE.getValue()));
        sexTag.setValuestring(person.getA0105() == null ? DEFAULT_VALUE : person.getA0105());
        list.add(sexTag);
        if (person.getA0106() != null) {
            DPersontagEntity entity = new DPersontagEntity();
            entity.setPersonid(person.getFlowid());
            entity.setTagid(Long.valueOf(A01TagEnum.NIAN_LING.getValue()));
            entity.setValuestring(Integer.valueOf(AgeUtil.getCurrentAge(person.getA0106())).toString());
            list.add(entity);
        }
        DPersontagEntity minzuTag = new DPersontagEntity();
        minzuTag.setPersonid(person.getFlowid());
        minzuTag.setTagid(Long.valueOf(A01TagEnum.MIN_ZU.getValue()));
        minzuTag.setValuestring((person.getA0130() == null || !person.getA0130().equals("汉族")) ? "少数民族" : "汉族");
        list.add(minzuTag);
        DPersontagEntity zhengzhimianmaoTag = new DPersontagEntity();
        zhengzhimianmaoTag.setPersonid(person.getFlowid());
        zhengzhimianmaoTag.setTagid(Long.valueOf(A01TagEnum.ZHENGZHI_MINAMAO.getValue()));
        zhengzhimianmaoTag.setValuestring(isDigit(person.getA0184a()) ? "中共" : "非中共");
        list.add(zhengzhimianmaoTag);
        DPersontagEntity zhijiTag = new DPersontagEntity();
        zhijiTag.setPersonid(person.getFlowid());
        zhijiTag.setTagid(Long.valueOf(A01TagEnum.ZHI_JI.getValue()));
        zhijiTag.setValuestring(person.getA0179() == null ? DEFAULT_VALUE : person.getA0179());
        list.add(zhijiTag);
        DPersontagEntity ganbuleibieTag = new DPersontagEntity();
        ganbuleibieTag.setPersonid(person.getFlowid());
        ganbuleibieTag.setTagid(Long.valueOf(A01TagEnum.GANBU_LEIBIE.getValue()));
        ganbuleibieTag.setValuestring(person.getA0181() == null ? DEFAULT_VALUE : person.getA0181());
        list.add(ganbuleibieTag);
        if (person.getA0180() != null) {
            DPersontagEntity entity2 = new DPersontagEntity();
            entity2.setPersonid(person.getFlowid());
            entity2.setTagid(Long.valueOf(A01TagEnum.XIANREN_ZHIJINIANXIAN.getValue()));
            entity2.setValuestring(Integer.valueOf(AgeUtil.getCurrentAge(person.getA0180())).toString());
            list.add(entity2);
        }
        if (person.getA0185() != null) {
            DPersontagEntity entity3 = new DPersontagEntity();
            entity3.setPersonid(person.getFlowid());
            entity3.setTagid(Long.valueOf(A01TagEnum.REN_XIANZHI_NIANXIAN.getValue()));
            entity3.setValuestring(Integer.valueOf(AgeUtil.getCurrentAge(person.getA0185())).toString());
            list.add(entity3);
        }
        DPersontagEntity giguanTag = new DPersontagEntity();
        giguanTag.setPersonid(person.getFlowid());
        giguanTag.setTagid(Long.valueOf(A01TagEnum.JI_GUAN.getValue()));
        giguanTag.setValuestring(person.getA0108() == null ? DEFAULT_VALUE : person.getA0108());
        list.add(giguanTag);
        if (person.getA0176() != null && !"".equals(person.getA0176())) {
            String[] str = person.getA0176().split(",");
            for (String value : str) {
                DPersontagEntity entity4 = new DPersontagEntity();
                entity4.setPersonid(person.getFlowid());
                entity4.setTagid(Long.valueOf(A01TagEnum.SHUXI_LINGYU.getValue()));
                entity4.setValuestring(value);
                list.add(entity4);
            }
        }
        if (person.getA0177a() != null && !"".equals(person.getA0177a())) {
            String[] str2 = person.getA0177a().split(",");
            for (String value2 : str2) {
                DPersontagEntity entity5 = new DPersontagEntity();
                entity5.setPersonid(person.getFlowid());
                entity5.setTagid(Long.valueOf(A01TagEnum.LIREN_ZHONGYAO_JINGLIBIAOSHI.getValue()));
                entity5.setValuestring(value2);
                list.add(entity5);
            }
        }
        return list;
    }

    private boolean isDigit(String str) {
        if (str == null) {
            return false;
        }
        return Pattern.compile("\\d{1,}.*").matcher(str).matches();
    }
}
